<?php
namespace app\qianyu\model;
use think\Db;
use think\Model;

class Park extends Model
{
    protected $table = 'cbdd_park';

    //获取首页订单
    public function getParkListData($param){
        $list = $this->where('citycode',$param)->select();
        return $list;
    }
    //获取首页订单
    public function getParkDetailData($param){
        $data = $this->where('id',$param)->find();
        $park_type = config('park_type');
        if($data){
            $typeList = explode(',', $data['type']);
            if(count($typeList) > 1){
                if(array_key_exists($typeList[0], $park_type)){
                   $data['park_info1'] = $typeList[0] == 1 ? $park_type[$typeList[0]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['indoor_price'] / 100 .'元' ) : ($data['indoor_price'] / 100 .'元')) : $park_type[$typeList[0]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['outdoor_price'] / 100 .'元' ) : ($data['outdoor_price'] / 100 .'元'));

                }else{
                    $data['park_info1'] = '';
                }

                if(array_key_exists($typeList[1], $park_type)){
                   $data['park_info2'] = $typeList[1] == 1 ? $park_type[$typeList[1]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['indoor_price'] / 100 .'元' ) : ($data['indoor_price'] / 100 .'元')) : $park_type[$typeList[0]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['outdoor_price'] / 100 .'元' ) : ($data['outdoor_price'] / 100 .'元')) ;
                }else{
                    $data['park_info2'] = '';
                }

                if($typeList[0] == 1){
                    $data['show_indoor_park'] = $park_type[$typeList[0]];
                    $data['show_indoor_price'] = $data['price_type'] == 1 ? ($data['day'] * $data['indoor_price'] ) : ($data['indoor_price']);
                }elseif($typeList[0] == 2){
                    $data['show_outdoor_park'] = $park_type[$typeList[0]];
                    $data['show_outdoor_price'] = $data['price_type'] == 1 ? ($data['day'] * $data['outdoor_price'] ) : ($data['outdoor_price']);
                }
                if($typeList[1] == 2){
                    $data['show_outdoor_price'] = $data['price_type'] == 1 ? ($data['day'] * $data['outdoor_price'] ) : ($data['outdoor_price']);
                }elseif($typeList[1] == 1){
                    $data['show_indoor_park'] = $park_type[$typeList[1]];
                    $data['show_indoor_price'] = $data['price_type'] == 1 ? ($data['day'] * $data['indoor_price'] ) : ($data['indoor_price']);
                }
                $show_typeList = [];
                $typeList[2] = 1;
                foreach ($typeList as $key => &$value) {
                    if(!array_key_exists($value, $park_type)){
                        foreach ($park_type as $k => $v) {
                            unset($park_type[$value]);
                        }
                    }
                }
            $data['show_type'] = $park_type;
            }else{
                if(array_key_exists($typeList[0], $park_type)){
                   $data['park_info1'] =   $typeList[0] == 1 ? $park_type[$typeList[0]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['indoor_price'] / 100 .'元' ) : ($data['indoor_price'] / 100 .'元')) : $park_type[$typeList[0]] . ':' . $data['day'] . '天起停共' . (($data['price_type'] == 1) ? ($data['day'] * $data['outdoor_price'] / 100 .'元' ) : ($data['outdoor_price'] / 100 .'元'));
                }else{
                    $data['park_info1'] = '';
                }
                    $data['park_info2'] = '';
               $data['show_type'] = [$data['type'] => $park_type[$data['type']]];
            }
        }
        return $data;
    }
}